package middleware

import (
	"github.com/gin-gonic/gin"
	cors "github.com/rs/cors/wrapper/gin"
	"net/http"
)

func CORSMiddleware() gin.HandlerFunc {
	handler := cors.New(cors.Options{
		AllowedOrigins: []string{"*"},
		//AllowCredentials: true,
		AllowedMethods: []string{
			http.MethodGet,
			http.MethodPost,
			http.MethodPut,
			http.MethodPatch,
			http.MethodDelete,
			http.MethodOptions,
			http.MethodHead,
		},
		AllowedHeaders: []string{"*"},
		//AllowedHeaders: []string{"X-Token", "Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token", "Authorization", "accept", "origin", "Cache-Control", "X-Requested-With","Access-Control-Allow-Origin"},
		ExposedHeaders: []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "Cache-Control", "Content-Language", "Expires", "Last-Modified", "Pragma", "FooBar"},
		MaxAge:         18000,
		Debug:          true,
	})

	return handler
}
